class Solution(object):
    def backspaceCompare(self, s, t):
        """
        :type s: str
        :type t: str
        :rtype: bool
        """

        def build(string):
            ans = []
            for i in string:
                if i != '#':
                    ans.append(i)
                else:
                    if ans:
                        ans.pop()
            return ans

        return build(s) == build(t)


if __name__ == '__main__':
    print(Solution().backspaceCompare("ab##", "c#d#"))
